package pumpeddevs.game.wishbone.sprites;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.widget.HeterogeneousExpandableList;
import pumpeddevs.game.framework.PDActivity;
import pumpeddevs.game.framework.PDLoadingBar;
import pumpeddevs.game.framework.PDSprite;
import pumpeddevs.game.framework.PDStage;
import pumpeddevs.game.wishbone.R;
import pumpeddevs.game.wishbone.stage1.Stage1;

public class LoadingPage extends PDStage{
	
	protected PDLoadingBar _loadLoadingBar;
	private GenericSprite _loadingBackGroud;
	private boolean _isAlreadyRender = false;
	
	public LoadingPage(PDActivity context, int width, int height, int numberOfProcess) {
		super(context, width, height);
		this._loadingBackGroud = new GenericSprite(context, R.drawable.loadingbackground);
//		Bitmap bitmap = Bitmap.createScaledBitmap(this._loadingBackGroud.getBitmap(), width, height, true);
		this._loadingBackGroud.setBitmap(Bitmap.createScaledBitmap(this._loadingBackGroud.getBitmap(), width, height, true));
		this._loadingBackGroud.setCoordinate(0, 0);
		
		this._loadLoadingBar = new PDLoadingBar(context, R.drawable.loadingboneyellow, 
				R.drawable.loadingbone, numberOfProcess);
//		this._loadLoadingBar.set
		this._loadLoadingBar.setCoordinate((width - this._loadLoadingBar.getBitmap().getWidth())/2, 
				height - this._loadLoadingBar.getBitmap().getHeight() - 100);
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void render(Canvas canvas) {
		this._loadingBackGroud.render(canvas);
		this._loadLoadingBar.render(canvas);
		this._isAlreadyRender = true;
	}

	@Override
	protected void updatePhysics() {
		if(this._isAlreadyRender) {
			try {
				Thread.sleep(500);
				this._loadLoadingBar.incrementFinishProcess();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	
		}
		if(this._loadLoadingBar.isFinishLoading()) {
//			Stage1 stage1 = new Stage1(this._context, this._screenWidth, this._screenHeight); 
//			this._context.setContentView(stage1);
			this.setFinish(true);
			this._context.nextStage();
		}
		
	}


	
}
